#include "linerelation.h"

lineRelation::lineRelation(QGraphicsLineItem *line,QGraphicsTextItem *rname,QGraphicsTextItem *rtype1,QGraphicsTextItem *rtype2,QGraphicsProxyWidget *w1,QGraphicsProxyWidget *w2,QObject *parent) : QObject(parent)
{
    this->line=line;
    this->nametext=rname;
    this->type1text=rtype1;
    this->type2text=rtype2;
    this->proxy1=w1;
    this->proxy2=w2;
}


void lineRelation::update(){
    // 计算两个QListWidget控件的中心位置
    QPointF center1 = proxy1->mapToScene(proxy1->boundingRect().center());
    QPointF center2 = proxy2->mapToScene(proxy2->boundingRect().center());
    // 更新直线的位置
    line->setLine(center1.x(), center1.y(), center2.x(), center2.y());
    // 移动文本到线的中点
//    QPointF center = (line->line().p1() + line->line().p2()) / 2+QPointF(-10,10);
//    QPointF center3 = (line->line().p1() + line->line().p2()) / 2+QPointF(-10,-10);
    QPointF center11 = line->line().pointAt(0.35);
    QPointF center22 = line->line().pointAt(0.65);
    type1text->setPos(center11);
    type2text->setPos(center22);
    //QPointF center3 = (line->line().p1() + line->line().p2()) / 2+QPointF(-10,-10);
    QPointF center3 = line->line().pointAt(0.5);
    nametext->setPos(center3);
}
